using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using Microsoft.SharePoint;
using System.Diagnostics;

namespace IWCommunity.Blogs.WebControls
{
    public class BlogContext
    {
        //private BlogSettings _settings;
        //private Nullable<int> _timeOffset = null;
        //private Nullable<bool> _blogEnabledSite = null;
        //private string _currentTheme = null;

       // public static Guid BlogFeatureGUID = new Guid("BBE9DEF7-2FE9-A0B1-D7BB-AA128C837EBE");
       // public static Guid BlogThemeFeatureGUID = new Guid("BBE9DEF7-2FE9-A0B1-D712-AA128C837EBE");
       // public static Guid BlogLinkbackFeatureGUID = new Guid("174AC416-59EC-4D9A-9157-F981106B5EBE");

        //public bool BlogEnabledSite
        //{
        //    get 
        //    {
        //        try
        //        {
        //            if (_blogEnabledSite.HasValue) return _blogEnabledSite.Value;

        //            if (SPContext.Current.Web == null) return false;

        //            _blogEnabledSite = (SPContext.Current.Web.Features[BlogContext.BlogFeatureGUID] != null);

        //            if (!Settings.BlogExtensionsEnabled) _blogEnabledSite = false;

        //            return _blogEnabledSite.Value;
        //        }
        //        catch (Exception ex)
        //        {
        //            Debug.WriteLine(ex);
        //            return false;
        //        }
        //    }
        //}

        public virtual bool IsBlogOwner
        {
            get

            {
                return SPContext.Current.Web.DoesUserHavePermissions(SPBasePermissions.ApproveItems | SPBasePermissions.AddListItems);
               // return SPContext.Current.Web.UserIsWebAdmin; //changed my MODONOVAN
            }
        }

        //public int ClientTimeZoneOffsetFromWeb
        //{
        //    get
        //    {
        //        try
        //        {
        //            if (!_timeOffset.HasValue)
        //            {
        //                HttpCookie oCookie = HttpContext.Current.Request.Cookies["CksEbeTZ"];
        //                if (oCookie != null)
        //                {
        //                    int iWeb = SPContext.Current.Web.RegionalSettings.TimeZone.Information.DaylightBias;
        //                    _timeOffset = iWeb - int.Parse(oCookie.Value);
        //                }
        //                else
        //                    _timeOffset = 0;
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            Debug.Write(ex);
        //            _timeOffset = 0;
        //        }

        //        return _timeOffset.Value;
        //    }
        //}

        //public DateTime ClientDateFromWebDate(DateTime webDate)
        //{
        //    //return SPContext.Current.Web.RegionalSettings.TimeZone.LocalTimeToUTC(webDate).AddMinutes(ClientTimeZoneOffsetFromWeb);
        //    return webDate.AddMinutes(ClientTimeZoneOffsetFromWeb);
        //}

        //public BlogSettings Settings
        //{
        //    get { if (_settings == null) _settings = new BlogSettings(); return _settings; }
        //}

        public static BlogContext Current
        {
            get
            {
                BlogContext bc = (BlogContext)HttpContext.Current.Items["ebeBlogContext"];
                if (bc == null)
                {
                    bc = new BlogContext();
                    HttpContext.Current.Items["ebeBlogContext"] = bc;
                }

                return bc;
            }
        }

        //public API.IUrlProvider UrlProvider
        //{
        //    get { return new DefaultUrlProvider(); }
        //}

        //public string BlogThemeVariation
        //{
        //    get
        //    {
        //        HttpCookie oCookie = HttpContext.Current.Request.Cookies["ebeBlogThemeVariation"];

        //        string sVariation = (oCookie == null) ? "" : oCookie.Value;

        //        if (string.IsNullOrEmpty(sVariation))
        //            sVariation = Settings.BlogThemeVariation;

        //        if (string.IsNullOrEmpty(sVariation)) sVariation = "Default";

        //        return sVariation;
        //    }
        //}

        //public string BlogTheme
        //{
        //    get
        //    {
        //        if (!string.IsNullOrEmpty(_currentTheme)) return _currentTheme;

        //        if (!string.IsNullOrEmpty(HttpContext.Current.Request["theme"]) && BlogContext.Current.Settings.ThemeSelectorEnabled) return HttpContext.Current.Request["theme"];

        //        HttpCookie oCookie = HttpContext.Current.Request.Cookies["ebeBlogTheme-" + SPContext.Current.Web.Url];

        //        _currentTheme = (oCookie == null) ? "" : oCookie.Value;

        //        if (string.IsNullOrEmpty(_currentTheme))
        //            _currentTheme = Settings.BlogTheme;

        //        if (string.IsNullOrEmpty(_currentTheme)) _currentTheme = "Default";

        //        return _currentTheme;
        //    }
        //}
    }
}
